$(function () {
    $(".head").load("head.html")
    $(".top").load("gw.html")

    //拿地址后面的参数
    function getData(){
        if(document.URL.indexOf("?")<0) return;//获取当前url地址,如果没参数.直接返回
        var str=document.URL.split("?")[1];
        var obj={};
        var arr;
        //当只有一个参数传过来时
        if(str.indexOf("&")<0){
            if(str.indexOf("=")<0) return;
            arr=str.split("=");
            obj[arr[0]]=arr[1];
            return obj;
        }
        //当有多个参数时
        arr=str.split("&");
        var arr1;
        for(var i=0;i<arr.length;i++){
            arr1=arr[i].split("=");
            obj[arr1[0]]=arr1[1];
        }
        return obj;
    }
    var obj=getData();
    var fl =unescape(obj.fl);
    console.log(fl)
    // $(".fen").html(fl)
    $.post("news/spXQ",{"id":obj.id},function (data) {
        $("#MagicZoom").attr("href","../../files/"+data.filename+"")
        $("#tsImgS").find("img").attr("src","../../files/"+data.filename+"")
        console.log(data)
        $(".pro_des").append(
            " <div class=\"des_name\">\n" +
            "<p>"+data.name+"</p>\n" +
            ""+data.description+"" +
            "</div>\n" +
            "<div class=\"des_price\">\n" +
            "本店价格：<b>￥"+data.price+"</b><br />\n" +
            "库存：<span>"+data.stock+"</span>\n" +
            "</div>\n" +
            "<div class=\"des_choice\">\n" +
            "<span class=\"fl\">型号选择：</span>\n" +
            "<ul>\n" +
            "<li class=\"checked\">30ml<div class=\"ch_img\"></div></li>\n" +
            "<li>50ml<div class=\"ch_img\"></div></li>\n" +
            "<li>100ml<div class=\"ch_img\"></div></li>\n" +
            "</ul>\n" +
            "</div>\n" +
            "<div class=\"des_choice\">\n" +
            "<span class=\"fl\">颜色选择：</span>\n" +
            "<ul>\n" +
            "<li>红色<div class=\"ch_img\"></div></li>\n" +
            "<li class=\"checked\">白色<div class=\"ch_img\"></div></li>\n" +
            "<li>黑色<div class=\"ch_img\"></div></li>\n" +
            "</ul>\n" +
            "</div>\n" +
            "<div class=\"des_share\">\n" +
            "<div class=\"d_sh\">\n" +
            "分享\n" +
            "<div class=\"d_sh_bg\">\n" +
            "                        <a href=\"#\"><img src=\"images/sh_1.gif\" /></a>\n" +
            "                        <a href=\"#\"><img src=\"images/sh_2.gif\" /></a>\n" +
            "                        <a href=\"#\"><img src=\"images/sh_3.gif\" /></a>\n" +
            "                        <a href=\"#\"><img src=\"images/sh_4.gif\" /></a>\n" +
            "                        <a href=\"#\"><img src=\"images/sh_5.gif\" /></a>\n" +
            "                    </div>\n" +
            "                </div>\n" +
            "                <div class=\"d_care\"><a onclick=\"ShowDiv('MyDiv','fade')\">关注商品</a></div>\n" +
            "            </div>\n" +
            "            <div class=\"des_join\">\n" +
            "                <div class=\"j_nums\">\n" +
            "                    <input type=\"text\" value=\"1\" name=\"\" class=\"n_ipt\" data-kucun='"+data.stock+"'/>\n" +
            "                    <input type=\"button\" value=\"\" onclick=\"addUpdate(jq(this));\" class=\"n_btn_1\" />\n" +
            "                    <input type=\"button\" value=\"\" onclick=\"jianUpdate(jq(this));\" class=\"n_btn_2\" />\n" +
            "                </div>\n" +
            "                <span class=\"fl\"><a data-id='"+data.id+"' href='javascript:;' id='jrGWC'><img src=\"images/j_car.png\" /></a></span>\n" +
            "            </div>"
        )
        $("#jrGWC").click(function () {
            $.post("news/gwcSP",{"id":$(this).data('id'),"number":$(".n_ipt").val()},function (data) {
                confirm(data.msg)
                location.reload()
            })
        })
        $(".n_ipt").blur(function () {
            if ($(".n_ipt").val()>$(this).data('kucun')){
                alert("库存不足")
                $(".n_ipt").val(1)
            }
            if (isNaN($(".n_ipt").val())){
                $(".n_ipt").val(1)
            }
        })

    })
})